package com.chanyachting.emall.action.club;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.chanyachting.emall.domain.Company;
import com.chanyachting.emall.domain.Dock;
import com.chanyachting.emall.domain.Docksell;
import com.chanyachting.emall.form.CompanyForm;
import com.chanyachting.emall.service.CompanyService;
import com.chanyachting.emall.service.DockSellService;
import com.chanyachting.emall.service.DockyachtService;
import com.chanyachting.emall.serviceImpl.CompanyServiceImpl;
import com.chanyachting.emall.serviceImpl.DockSellServiceImpl;
import com.chanyachting.emall.serviceImpl.DockyachtServiceImpl;

public class ReadCompanyOfOneProdAction  extends Action{
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		CompanyService comService = new CompanyServiceImpl();
		DockyachtService dyService = new DockyachtServiceImpl();
		DockSellService dsService = new DockSellServiceImpl();

		CompanyForm tForm = (CompanyForm)form;
		if(tForm.getId() == null || "".equals(tForm.getId())) {
			return mapping.findForward("error");
		}
		if(tForm.getProductId() == null || "".equals(tForm.getProductId())) {
			return mapping.findForward("error");
		}
		
		List<Company> alList = null;
		Dock d = null;
		alList = comService.getCompanyById(tForm.getId().toString());
		d = dyService.QueryOneDock(tForm.getProductId());
		if (alList.size() == 0) {
			return mapping.findForward("error");
		}
		if (d == null) {
			return mapping.findForward("error");
		}
		
		System.out.println("ReadCompanyOfOneProdAction:d.getId()=" + d.getId());
		List<Docksell> dsList = dsService.QueryDockSellByDockId(String.valueOf(d.getId()));
		
		tForm.setDockSellList(dsList);
		tForm.setComp(alList.get(0));
		tForm.setDock(d);
		return mapping.findForward("readProduct01");
	}
}
